package com.snake.excel2java.excel.util;

import java.util.List;
import java.util.Map;

public class StringUtil {
	
	public static final String SPLIT_COMMA = ",";
	public static final String SPLIT_COLON = ":";
	
	public static String toString(List<Pair> foodList, StringBuilder sb) {
		
		sb.delete(0, sb.length());
		
		for(Pair pair: foodList) {
			
			if(sb.length() > 0)
				sb.append(SPLIT_COMMA);
			
			sb.append(pair.getKey())
			  .append(SPLIT_COMMA)
			  .append(pair.getValue());
		}
		
		return sb.toString();
	}
	
	public static void splitToMap(String str, String split, Map<Integer, Integer> map) {
		
		String[] tempArr = str.split(split);
		
		int index = 0;
		while(index < tempArr.length) 
			map.put(Integer.parseInt(tempArr[index++]), Integer.parseInt(tempArr[index++]));
	
		
	}
	
	public static void splitToArray(String str, String split,  List<Integer> list) {
		
		String[] tempArr = str.split(split);
		
		for(String tempStr: tempArr) 
			list.add(Integer.parseInt(tempStr));

	}
	
	public static String[] split(String str, String split) {
		
		return str.split(split);

	}

}
